﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using LightSwitchApplication.UserCode;
namespace LightSwitchApplication
{
    public partial class Home
    {
        partial void Home_Created()
        {
            // Write your code here.
            var appList = this.DataWorkspace.LSWData.AppConfigs.GetQuery();   
            var getConfig = appList.Execute();

            var list = getConfig.Select(t => new { t.ID, t.Name }).ToDictionary(t => t.ID, t => t.Name);
            Global._URLService = list["URLService"];
            Global._URLReport = list["URLReport "];
        }

        void Home_ControlAvailable(object sender, ControlAvailableEventArgs e)
        {
            System.Windows.Controls.TextBlock text = e.Control as System.Windows.Controls.TextBlock;
            if(text !=null)
            {
                text.FontSize = 16;
                text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 0, 0, 255));
                text.FontWeight = System.Windows.FontWeights.Bold;
                text.Text = "Công ty TNHH SX TM DV và ĐT ĐỨC THỊNH";

            }
        }

        partial void Home_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            // Write your code here.
            this.Logo = ImageHelper.GetImageByName("Resources/computer.png");
            this.imgPayment = ImageHelper.GetImageByName("Resources/Payment.png");
            this.imgPurchase = ImageHelper.GetImageByName("Resources/Purchase.png");
            this.imgReciept = ImageHelper.GetImageByName("Resources/Reciept.png");
            this.imgSales = ImageHelper.GetImageByName("Resources/Sales.png");
            this.imgTimeSheet = ImageHelper.GetImageByName("Resources/TimeSheet.png");
            this.FindControl("lblLogo").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(Home_ControlAvailable); 
        }

        partial void GoTimeSheet_Execute()
        {
            // Write your code here.
            this.Application.ShowTimeSheetsEmployeesLoadsEditGrid();  
        }

        partial void GoNewSalesOrder_Execute()
        {
            // Write your code here.
            this.Application.ShowSalesOrdersListDetail(true); 
        }

        partial void GoNewPurchase_Execute()
        {
            // Write your code here.
            this.Application.ShowPurchaseOrdersListDetail(true);
        }

        partial void GoNewCashReciept_Execute()
        {
            // Write your code here.
            this.Application.ShowRecieptListByRefListDetail(null, true);  
        }

        partial void GoNewCashPayment_Execute()
        {
            // Write your code here.
            this.Application.ShowPaymentListsListDetail(null, true);  
        }
    }
}
